package com.fjh.springboot_01.mapper;

import com.fjh.springboot_01.pojo.lesson.LessonFavorite;
import org.apache.ibatis.annotations.*;

@Mapper
public interface LessonFavoriteMapper {
    // 添加收藏记录
    @Insert("INSERT INTO lesson_favorite(lesson_id, user_id, create_time) VALUES(#{lessonId}, #{userId}, #{createTime})")
    void add(LessonFavorite lessonFavorite);

    // 删除收藏记录
    @Delete("DELETE FROM lesson_favorite WHERE lesson_id = #{lessonId} AND user_id = #{userId}")
    void delete(@Param("lessonId") Integer lessonId, @Param("userId") Integer userId);

    // 查询用户是否收藏了某课程
    @Select("SELECT COUNT(*) FROM lesson_favorite WHERE lesson_id = #{lessonId} AND user_id = #{userId}")
    Integer exists(@Param("lessonId") Integer lessonId, @Param("userId") Integer userId);

    // 查询课程收藏数量
    @Select("SELECT COUNT(*) FROM lesson_favorite WHERE lesson_id = #{lessonId}")
    Integer count(@Param("lessonId") Integer lessonId);
    
    // 获取用户收藏的课程ID列表
    @Select("SELECT lesson_id FROM lesson_favorite WHERE user_id = #{userId} ORDER BY create_time DESC")
    java.util.List<Integer> getUserFavoriteIds(@Param("userId") Integer userId);
} 